Enter a number ? 17 The number is zero or positive Positive numbers are > 0 Bye
The TRUE branch was executed because the answer to the
question NUMBER >= 0
was TRUE.
The true branch consists of two statements this time.
Here is how an outline of how to make a two-way decision:
... statements done before the decision ' IF condition THEN .... ' true branch .... .... ' true branch ELSE .... ' false branch .... .... ' false branch END IF ' ... statements done after the branch comes back together
Here are some details:
IF condition THEN
must be on one line.ELSE
statement must be by itself on a line.
END IF
statement must be by itself on a line.
The condition looks like the part of a DO WHILE condition
statement that compares what is held in a variable with other values.
You can use the same comparisons: <, <=, =,
and so on.
Is the following program correct?
PRINT "Enter a Number" INPUT NUMBER ' IF NUMBER >= 0 THEN PRINT "The square root is:", SQR( NUMBER ) ELSE PRINT "There is no square root" PRINT "Run the program again." END IF ' PRINT "Bye" END